package com.ctshk.rpc.air.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ctshk.rpc.air.dto.AirBookingListQueryDTO;
import com.ctshk.rpc.air.dto.AirProductListDTO;
import com.ctshk.rpc.air.dto.AirRecommendListDTO;
import com.ctshk.rpc.air.entity.AirProduct;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * <p>
 * 机票产品 Mapper 接口
 * </p>
 *
 * @author lihang
 * @since 2021-03-05
 */
public interface AirProductMapper extends BaseMapper<AirProduct> {

    /**
     * 查詢機票推薦列表
     * @param page
     * @param queryWrapper
     * @return
     */
    @Select("SELECT p.id,f.company_id,f.company_name,f.dep_city_id,f.dep_city_name,\n" +
            "f.arr_city_id,f.arr_city_name,f.dep_airport_id,f.dep_airport_name FROM  t_air_product p LEFT JOIN t_air_flight f ON  p.route_id = f.id"+
            " ${ew.customSqlSegment} ORDER BY p.gmt_create DESC")
    Page<AirRecommendListDTO>  queryRecommend(Page<AirRecommendListDTO> page, @Param("ew") Wrapper queryWrapper);


    /**
     * 查詢機票预订列表
     * @param page
     * @param queryWrapper
     * @return
     */
    @Select("SELECT tf.id AS flight_id, tf.company_id,tf.company_name,tf.flight_number,tf.airplane_name,tf.dep_city_id,tf.dep_city_name,\n" +
            "tf.arr_city_id,tf.arr_city_name,tf.arr_airport_id,tf.arr_airport_name,tf.dep_airport_id,\n" +
            "tf.dep_airport_name,tf.dep_time,tf.arr_time,tf.airplane_name,tp.id as product_id,tp.cabin_class,tp.cabin_name,\n" +
            "tp.supplier_id,tp.supplier_name\n" +
            "FROM t_air_product tp  LEFT JOIN t_air_flight tf  ON tf.id = tp.route_id"+
            " ${ew.customSqlSegment} ORDER BY tp.gmt_create DESC")
    Page<AirBookingListQueryDTO>  queryBooking(Page<AirBookingListQueryDTO> page, @Param("ew") Wrapper queryWrapper);


    @Select("SELECT tp.id,tp.`code`,tf.flight_number,tf.company_name,tf.company_id,\n" +
            "tf.dep_city_id,tf.dep_city_name,tf.arr_city_id,tf.arr_city_name,tf.dep_airport_id,\n" +
            "tf.dep_airport_name,tf.arr_airport_id,tf.arr_airport_name,\n" +
            "tf.dep_time,tf.arr_time,tp.cabin_class,tp.cabin_name,\n" +
            "tp.supplier_id,tp.supplier_name,tp.charge_user_id,tp.applicable_crowd_id,\n" +
            "tp.applicable_crowd_name,tp.pack_status,tp.approval_status,tp.sell_status,\n" +
            "tp.recommend_status,tp.source,tp.route_id\n" +
            " FROM t_air_product tp  LEFT JOIN t_air_flight tf  ON tf.id = tp.route_id"+
            " ${ew.customSqlSegment} ORDER BY tp.gmt_create DESC")
    Page<AirProductListDTO>  queryProcutList(Page<AirProductListDTO> page, @Param("ew") Wrapper queryWrapper);
}
